home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / pgm_tool / lu62 / novell / appl.c next >
C/C++ Source or Header  |  1995-07-03  |  15KB  |  444 lines

  1.  
  2.   /************************************************************************
  3.                          APPL
  4.   **************************************************************************/
  5.  
  6.   #include <stdio.h>
  7.   #include <memory.h>
  8.   #include <string.h>
  9.   #include <include.h>
  10.   #include <malloc.h>
  11.   #include <state1.h>
  12.   #include <dos.h>
  13.   #define RESRU 19
  14.   #define RESRH 16
  15.   #define APPC 0x68            /* 1068 */
  16.  
  17.  
  18. extern struct segprf *preqseg(int );
  19. extern struct rqb *preqrq(int );
  20. extern void pattach(int ,char far *,int );
  21. extern void prelseg(struct segprf *);
  22. extern void prelrq(struct rqb *);
  23. extern void delhscb(struct hscb *);
  24.  
  25.  
  26.   extern struct rqb *appl1(struct rqb *);
  27.   struct rqb *apost(short,short,unsigned char);
  28.  
  29.   void Call_APPC(unsigned char,void far *);
  30.  
  31.   struct rqb *findrqb(char *(*pq),short syscr);
  32.   int bu_seg(short, unsigned char ,char *,struct hscb *);
  33.  
  34. extern struct hscb *crhscb( char *, char *);
  35. extern struct hscb *findhscb( unsigned long );
  36. extern struct hscb *fndhsad(char *);
  37.      int rqbind(struct rqb *);
  38.      int unbnd(struct rqb *);
  39.      int rqsend(struct rqb *);
  40.      int rspbind(struct rqb *);
  41.      int rspunbnd(struct rqb *);
  42.  
  43.  
  44.  
  45.   struct rqb *appl(struct rqb *wrqb)
  46.   {
  47.      int n,rtncd;
  48.      struct rh *wrh;
  49.      union ru *wru;
  50.  
  51.      if (!(wrqb->th.ra.code & FROM))
  52.             {
  53.                      return (appl1(wrqb));
  54.             }
  55.      wru=(char*)wrqb+RESRU;
  56.      wrh=(char*)wrqb+RESRH;
  57.      if (wrh->rh[0] & RSP)
  58.          goto RESP;
  59.      if ((wrh->rh[0] == 0x6b) & (wrh->rh[1] == 0x80) )
  60.           {
  61.               if (wru->cru[0]==0x31) {
  62.           rtncd=rqbind(wrqb); goto BAC; }
  63.               if (wru->cru[0]==0x32) {
  64.           rtncd=unbnd(wrqb); goto BAC; }
  65.          }
  66.      rtncd=rqsend(wrqb);
  67.      goto BAC;
  68.      RESP: n=0;
  69.            if (wrh->rh[1] & ERTI)
  70.                 n=2;
  71.            if (wru->cru[n]==0x31) {
  72.           rtncd=rspbind(wrqb);goto BAC; }
  73.            if (wru->cru[n]==0x32) {
  74.           rtncd=rspunbnd(wrqb);goto BAC;}
  75.            rtncd=rqsend(wrqb);
  76.      BAC:
  77.       return 0;
  78.      } /************ end of APPL ***************/
  79.      /**************** BIND ******************/
  80.      int rqbind(struct rqb *wrqbb)
  81.      {
  82.      struct segprf *wseg;
  83.      struct rqb *wpost;
  84.      union ru *wru;
  85.      struct bind *wbind;
  86.      struct hscb *whscb;
  87.      struct rh *wrh;
  88.      struct th *wth;
  89.  
  90.      wbind=(char*)wrqbb+RESRU;
  91.      wseg = (struct segprf *)((char *)wrqbb - 12);
  92.      wseg -> len = 4;
  93.      wth = &(wrqbb -> th.th);
  94.      wth -> t912.old.dcf = 4;
  95.      whscb=crhscb(wbind->slu,wbind->plu);
  96.      wrh=(char*)wrqbb+RESRH;
  97.      wrh->rh[0] |= RSP;
  98.      wrh->rh[1]=0;
  99.      if ( whscb == NULL){
  100.         wrh -> rh[1] |= ERTI;
  101.         wru = (char*)wrqbb + RESRU;
  102.         wru -> cru[2] = 0x31;
  103.      }
  104.      wrqbb->link=NULL;                     /* 0172 */
  105.      wrqbb->th.ra.stcb=FISC_CODE;
  106.      wrqbb->th.ra.code=0x02;
  107.      wrqbb->th.ra.code |= FROM;        /* 0172 */
  108.      memcpy ( wseg -> net_ad, whscb -> part_net_ad,6);
  109.      pattach (1,wrqbb,4);
  110.      wpost=apost(1,11,1);         /* 0279 */
  111.      if (wpost==NULL)
  112.         return 0;
  113.      wpost->th.ra.wa.hh.hscb=whscb->cor;
  114.      wru=(char*)wpost+RESRU;
  115.      memcpy (wru,&(whscb->hslunam[0]),8);
  116.      Call_APPC (1,wpost);       /*@2003 */
  117.      return 0 ;
  118.  
  119.      }/***************** end of bind **************/
  120.      /****************** RSP(BIND) **************/
  121.      int rspbind(struct rqb *wrqbrb)
  122.      {
  123.     struct rqb *wpost;
  124.         struct rh *wrh;
  125.         union ru *wru,*wrup;
  126.         struct hscb *whscb;
  127.         struct bind *wbind;
  128.     struct rqb *wrqbq;
  129.     struct th *wth;
  130.         struct nau *wnau;
  131.         struct segprf *wseg;
  132.  
  133.           wseg=(struct segprf *)((char*)wrqbrb-12);
  134.           wrh=(char*)wrqbrb+RESRH;
  135.       wru=(char*)wrqbrb+RESRU;
  136.       wth=&(wrqbrb->th.th);
  137.           if((whscb=fndhsad(wseg->net_ad)) == NULL)
  138.         return (-1);
  139.       wnau = whscb -> naup;
  140.           if ((wrh->rh[1] & ERTI) == 0)
  141.                 goto POSRSP;
  142.           wbind=&(wru->cru[2]);
  143.              wseg->link=NULL;   /*5002*/
  144.              wrqbrb->link=NULL; /*5002*/
  145.           prelseg(wseg);
  146.             wrqbq=findrqb(&(wnau->opnq),wth->t912.old.snf); /* 1068 */
  147.           if (wrqbq==NULL)
  148.                 return 0;
  149.           wrqbq->th.ra.rparm.parm.parm1=5;
  150.           wrqbq->th.ra.rparm.parm.parm2=0xff;
  151.           wrqbq->th.ra.code=0xda;
  152.           Call_APPC(5,wrqbq);     /* @2003 */
  153.            return 0;
  154.         POSRSP:
  155.            wrqbq=findrqb(&(wnau->opnq),wth->t912.old.snf);  /* 1068 */
  156.            if (wrqbq==NULL)
  157.               { wpost=apost(1,19,1);         /* 0279 */   /* 2005 */
  158.                 if(wpost==NULL)
  159.             return 0;
  160.                 wpost->th.ra.wa.hh.hscb=whscb->cor;
  161.                 wrup=(char*)wpost+RESRU;
  162.                  memcpy (wrup,&(whscb->hslunam[0]),8);
  163.                  memcpy (wrup+8,&(whscb->hsnodnam[0]),8);    /* 2005 */
  164.         Call_APPC(1,wpost);          /* @2003 */
  165.              wseg->link=NULL;   /*5002*/
  166.              wrqbrb->link=NULL; /*5002*/
  167.                 prelseg (wseg);
  168.                 return 0;
  169.               }
  170.           wrqbq->th.ra.rparm.parm.parm1=5;
  171.           wrqbq->th.ra.rparm.parm.parm2=0xff;
  172.           wrqbq->th.ra.code=0xc2;
  173.           wrqbq->th.ra.wa.hh.hscb=whscb->cor;
  174.          Call_APPC(5,wrqbq);        /* @2003  */
  175.              wseg->link=NULL;   /*5002*/
  176.              wrqbrb->link=NULL; /*5002*/
  177.           prelseg(wseg);
  178.           return 0;
  179.     }  /***************end of rsp(bind)**********************/
  180.     /********************** SEND ********************************/
  181.      int rqsend(struct rqb *wrqbs)
  182.     {
  183.         int i,k;
  184.         struct nau *wnau;
  185.         struct hscb *whscb;
  186.     unsigned char type;
  187.     struct rh *wrh;
  188.     union ru *wru;
  189.     char *pru,*prh;
  190.     struct segprf *wseg;
  191.  
  192.     wseg=(struct segprf *)((char*)wrqbs-12);
  193.     whscb=fndhsad(wseg->net_ad);
  194.     wnau=whscb->naup;
  195.     wrh=(char*)wrqbs+RESRH;
  196.     prh = wrh;
  197.     wru=(char*)wrqbs+RESRU;
  198.     pru = wru;
  199.     i=wseg -> len - 3 ;
  200.         if ( i == 0 )
  201.                 {
  202.                   if ( ((*prh & 0x0b) == 0x0b) && ((*(prh+1) & 0x80) == 0x80) )
  203.                         {
  204.                           type= Request_to_send;
  205.               bu_seg(0,type,NULL,whscb);
  206.                         }
  207.                   if ( ((*prh & 0x81) == 0x81) && ((*(prh+1) & 0xa0) == 0xa0) )
  208.                         {
  209.                           type= COnfirmed;
  210.                           bu_seg(0,type,NULL,whscb);
  211.                         }
  212.        if ( (*(prh+2) & 0x21 )  == 0 )
  213.             {   /* no change dir */
  214.                  if ( (((*prh) & 0x01 ) == 0x01) && (((*(prh+1)) & 0xa0) == 0xa0))
  215.                           { type = Confirm;
  216.                             bu_seg(0, type, NULL,whscb);
  217.                           }
  218.             }
  219.        if ( ((*(prh+2)) & 0x20) == 0x20 ) /* prep to rec */
  220.             {
  221.                 if ( (*(prh+1) & 0xb0 ) == 0x90)   /* flush */
  222.                            type = PREP_TO_RCV_FLUSH;
  223.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* short */
  224.                            type = PREP_TO_RCV_CONFIRM_SH;
  225.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* long */
  226.                            type = PREP_TO_RCV_CONFIRM_LG;
  227.                 bu_seg( 0, type,NULL,whscb);
  228.             }
  229.        if ( ((*(prh+2)) & 0x01 ) == 0x01)   /* deallocate */
  230.             {
  231.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* conf */
  232.                            type = Deallocate_confirm;
  233.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* flush */
  234.                            type = Deallocate_flush;
  235.                 bu_seg( 0, type,NULL,whscb);
  236.             }
  237.           goto ALLOK;
  238.                 }
  239.        if ( (*prh & 0x08) == 0x08 )   /* FMH */
  240.             { k= *pru;      /* FMH length */
  241.              type= Fmh;
  242.              bu_seg(k,type,pru,whscb);
  243.              if (i > k)      /* FMH + data */
  244.                     { memcpy (pru,pru+k,k);
  245.                       wseg -> len -= k;
  246.                     }
  247.              i -= k;
  248.             }
  249.  
  250.        if ( (*(prh+2) & 0x21 )  == 0 )
  251.             {   /* no change dir */
  252.                  if ( (((*prh) & 0x01 ) == 0x01) && (((*(prh+1)) & 0xa0) == 0xa0))
  253.                           { type = Confirm;
  254.                             bu_seg(0, type, NULL,whscb);
  255.                           }
  256.             }
  257.        if ( i != 0 )
  258.             {
  259.              type= Send_data;
  260.              bu_seg( i, type,pru,whscb);
  261.            }
  262.        if ( ((*(prh+2)) & 0x20) == 0x20 ) /* prep to rec */
  263.             {
  264.                 if ( (*(prh+1) & 0xb0 ) == 0x90)   /* flush */
  265.                            type = PREP_TO_RCV_FLUSH;
  266.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* short */
  267.                            type = PREP_TO_RCV_CONFIRM_SH;
  268.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* long */
  269.                            type = PREP_TO_RCV_CONFIRM_LG;
  270.                 bu_seg( 0, type,NULL,whscb);
  271.             }
  272.        if ( ((*(prh+2)) & 0x01 ) == 0x01)   /* deallocate */
  273.             {
  274.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* conf */
  275.                            type = Deallocate_confirm;
  276.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* flush */
  277.                            type = Deallocate_flush;
  278.                 bu_seg( 0, type,NULL,whscb);
  279.             }
  280.         ALLOK:
  281.         wseg->link = NULL;
  282.         wrqbs->link = NULL;
  283.         prelseg(wseg);
  284.              return 0;
  285.     } /******************************************************************/
  286.     bu_seg (short k,unsigned char t ,char *ptr,struct hscb *whscb)
  287.                 {
  288.                     struct  rqb *wpost;
  289.             struct nau *wnau;
  290.             struct segprf *wseg;
  291.             struct rh *wrh;
  292.             union ru *wru;
  293.                        wnau=whscb->naup;
  294.  
  295.                        if ( t == Fmh)
  296.                            wpost=apost(1,k+3,0);       /* 0279 */
  297.                        else
  298.                            wpost=apost(1,k+3,4);       /* 0279 */
  299.                        if (wpost==NULL)
  300.                             {
  301.                                 wpost = apost(0,0,7);
  302.                                 memcpy (&(wpost->th.ra.wa.area[0]),&(whscb->hslunam),8);
  303.             Call_APPC(7,wpost);       /* 1070 */
  304.                                  prelrq(wpost);
  305.                                  return 0;
  306.                              }
  307.                        memcpy (&(wpost->th.ra.wa.area[0]),&(whscb->hslunam),8);
  308.                        if (k != 0)
  309.                            {
  310.                  wru=(char*)wpost+RESRU;
  311.                  memcpy(wru,ptr,k);
  312.                            }
  313.                wrh=(char*)wpost+RESRH;
  314.                wrh->rh[0]= t ;
  315.         if (t == Fmh)
  316.               Call_APPC(0,wpost);       /* 1070 */
  317.         else
  318.                Call_APPC(4,wpost);     /* 1070 *//* @2003 */
  319.          wseg=(struct segprf *)((char*)wpost - 12);
  320.              wseg->link=NULL;   /*5002*/
  321.          wpost->link=NULL;  /*5002*/
  322.              prelseg(wseg);
  323.  
  324.         return 0;
  325.      }/************** end of bu_seg *******************/
  326.      unbnd(struct rqb *wrqbu)
  327.     {
  328.         struct rh *wrh;
  329.         struct rqb *wpost;
  330.         struct nau *wnau;
  331.         struct hscb *whscb;
  332.         struct segprf *wseg;
  333.         struct th *wth;
  334.  
  335.         wrh=(char*)wrqbu+RESRH;
  336.         wrh->rh[0] |= RSP;
  337.         wrh->rh[1]=0;
  338.         wseg = (struct segprf *)((char*)wrqbu-12);
  339.         wseg -> len = 4;
  340.         wth = &(wrqbu -> th.th);
  341.         wth -> t912.old.dcf = 4;
  342.         whscb=fndhsad( wseg->net_ad );
  343.         wnau=whscb->naup;                        /* @2002 */
  344.         wrqbu->th.ra.stcb=DFC_CODE;
  345.         wrqbu->th.ra.code=0x02;
  346.         wrqbu->th.ra.code|=FROM;
  347.         memcpy(wseg -> net_ad,whscb -> part_net_ad,6);
  348.         pattach(1,wrqbu,4);
  349.         wpost=apost(0,0,2);           /* 0279 */
  350.         if (wpost==NULL)
  351.         return 0;
  352.            memcpy (&(wpost->th.ra.wa.area[0]),&(whscb->hslunam),8);
  353.           Call_APPC(2,wpost);        /* @2003 */
  354.           delhscb(whscb);
  355.            return 0;
  356.       } /************** end of unbind ***************************/
  357.       /***************** RSP(UNBIND) ****************************/
  358.      int rspunbnd(struct rqb *wrqbru)
  359.      {
  360.         struct segprf *wseg;
  361.     struct hscb *whscb;
  362.  
  363.        wseg=(struct segprf *)((char*)wrqbru-12);
  364.        whscb=fndhsad(wseg->net_ad);
  365.           wseg->link=NULL;   /*5002*/
  366.           wrqbru->link=NULL;  /*5002*/
  367.        prelseg(wseg);
  368.        delhscb(whscb);
  369.        return 0;
  370.     }/***************** end of rsp(unbind) ************************/
  371.     /*************** request RQB or SEG for post *******************/
  372.     struct rqb *apost(short i,short k,unsigned char n)         /* 0279 */
  373.      {
  374.         struct rqb *wrqb;
  375.         struct segprf *wseg;
  376.         if (i==0) /* RQB */
  377.                 {wrqb=preqrq (1);
  378.                  if (wrqb==NULL)
  379.             {
  380.                          return (NULL);
  381.                         }
  382.                  wrqb->th.ra.code=0;
  383.                  wrqb->th.ra.code|=RTYPE;
  384.                }
  385.             else /* SEG */
  386.                 {
  387.                  wseg=preqseg(k);
  388.                  if (wseg == NULL)
  389.             {
  390.                          return (NULL);
  391.                         }
  392.                  wseg->link=NULL;
  393.                  wrqb=(struct rqb*)((char*)wseg+12);
  394.                  wrqb->th.ra.code=0;
  395.                  wseg->len=k;
  396.                }
  397.         wrqb->link=NULL;
  398.         wrqb->th.ra.code|=2;
  399.         wrqb->th.ra.code|=FROM;
  400.         wrqb->th.ra.rparm.parm.parm2=0xff;
  401.         wrqb->th.ra.rparm.parm.parm1=n;
  402.         return (wrqb);
  403.    }/******* end of post ************************/
  404.    /******** find RQB in queue *******************/
  405.    struct rqb *findrqb(char *(*pq),short syscr)
  406.   {
  407.         short usrcr;
  408.         struct rqb *prqb,*mrqb;
  409.             prqb=*pq;
  410.  
  411.  
  412.  
  413.             if (prqb==NULL)
  414.                     return (NULL);
  415.             memcpy (&usrcr,&(prqb->th.ra.wa.area[0]),2);
  416.             if (usrcr==syscr)
  417.                     {*pq=prqb->link;
  418.                       return (prqb);
  419.                     }
  420.             mrqb=prqb;
  421.             while (prqb->link!=NULL)
  422.                     {prqb=prqb->link;
  423.                      memcpy (&usrcr,&(prqb->th.ra.wa.area[0]),2);
  424.                      if (usrcr==syscr)
  425.                             {mrqb->link=prqb->link;
  426.                              return (prqb);
  427.                             }
  428.                      mrqb=prqb;
  429.                     }
  430.             return (NULL);
  431.      }/******* end of findrqb *****************/
  432. #if OS_TYPE == 0                 /* @2003 */
  433.     void Call_APPC(unsigned char RecForm,void far *p)
  434.          {
  435.             union REGS inregs,outregs;
  436.             struct SREGS segregs;
  437.                 inregs.x.ax=RecForm*256+255;
  438.                 segregs.ds=FP_SEG(p);
  439.                 inregs.x.dx=FP_OFF(p);
  440.                 int86x( APPC,&inregs,&outregs,&segregs);
  441.          }
  442. #endif                     /* @2003 */
  443.      /****************THE END*************************************/
  444.